package cn.modoumama.common.tools;

import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.internet.InternetAddress;

public class MyAuthenticator extends Authenticator{
    Address address =null;
    String userName=null;
    String password=null;

    public MyAuthenticator(){
    }
    public MyAuthenticator(String username, String password) {    
        this.userName = username;    
        this.password = password;    
    }

    public MyAuthenticator(String name, String userName, String password){
        this(userName,password);
        try {
            address =  new InternetAddress(userName, name, "UTF-8");
        } catch (Exception e) {
           throw new RuntimeException("初始化发送邮箱账户失败！~~~~~~");
        }
    }
    protected PasswordAuthentication getPasswordAuthentication(){   
        return new PasswordAuthentication(userName, password);   
    }

    public String getUserName() {
        return userName;
    }

    public Address getAddress() {
        return address;
    }
}